package org.tgit.gateway.common;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.springframework.cache.Cache;
import org.springframework.stereotype.Component;

@Component
public class CacheUtils {

    /**
     * 
     * @param gatewayCache
     * @param cackeKey
     * @param obj
     */
	public void  putCacheKeyValue(Cache gatewayCache,String cackeKey,Object obj){
		gatewayCache.put(cackeKey,obj);
	}

	/**
	 * 
	 * @param gatewayCache
	 * @param cackeKey
	 * @param str
	 */
	public void  putCacheKeyValue(Cache gatewayCache,String cackeKey,String str){
		gatewayCache.put(cackeKey,str);
	}
	/**
	 * 
	 * @param t
	 * @param objSet
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public  <T> Set<T> putSet(T t,Object... objSet){
		Set<T> s=new HashSet<T>();
		for (Object obj : objSet) {
			s.add((T) obj);
		}
		return s;
	}
    /**	
     * 
     * @param gatewayCache
     * @param objSet
     */
	
	/**
	 * 更新element对应的key的map值
	 * @param gatewayCache
	 * @param cacheKey
	 * @param key
	 * @param value
	 */
	
	@SuppressWarnings("unchecked")
	public void updateMapElement(Cache gatewayCache,String cacheKey,String key,String value){
	  Map<String,Object> map=(Map<String, Object>) gatewayCache.get(cacheKey).get();
	  map.put(key, value);
	  gatewayCache.put(cacheKey,map);
	}
}
